package edu.liu.db;

import java.sql.*;

public class DBMetaDataTester
{
	
	public static void main(String[] args) throws Exception
	{
		Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
		Connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://www.objectgraph.com:6464;DatabaseName=JavaTest","javatest","javatest");
		DatabaseMetaData dmd=con.getMetaData();
		
		System.out.println(dmd.getDatabaseProductName());
				
		//PrintResultSet(dmd.getCatalogs());
		
		//PrintResultSet(dmd.getTables("JavaTest",null,null,null));
		
		PrintResultSet(dmd.getColumns("JavaTest",null,"PhoneNumbers",null));
		
		con.close();
		
		
	}
	
	public static void PrintResultSet(ResultSet rs) throws Exception
	{
		ResultSetMetaData rsm=rs.getMetaData();
		int cols=rsm.getColumnCount();
		
		for(int i=0;i<cols;i++)
		{
			System.out.print(rsm.getColumnName(i+1)+"|");
		}
		
		System.out.println();
		System.out.println("-----------------------------");
		
		while(rs.next())
		{
			for(int i=0;i<cols;i++)
			{
				System.out.print(rs.getString(i+1)+"|");
			}
			System.out.println();
		}
		
		
		
	}

}
